﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KhoTNN
{
    public partial class frmCauHinhCSDL : Form
    {
        public frmCauHinhCSDL()
        {
            InitializeComponent();
        }

        private void frmCauHinhCSDL_Load(object sender, EventArgs e)
        {
            txtMayChu.Text = Properties.Settings.Default.MayChu;
            txtCSDL.Text = Properties.Settings.Default.CSDL;
            txtTaiKhoan.Text = Properties.Settings.Default.TaiKhoan;
            txtMatKhau.Text = Properties.Settings.Default.MatKhau;
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                var chuoiketnoi = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", txtMayChu.Text, txtCSDL.Text, txtTaiKhoan.Text, txtMatKhau.Text);
                Context db = new Context (chuoiketnoi );
                db.ExecuteQuery<string>("select table_name from information_schema.tables");
                MessageBox .Show ("Kết nối thành công!");
                Properties.Settings.Default.MayChu = txtMayChu.Text;
                Properties.Settings.Default.CSDL = txtCSDL.Text;
                Properties.Settings.Default.TaiKhoan = txtTaiKhoan.Text;
                Properties.Settings.Default.MatKhau = txtMatKhau.Text;
                Properties.Settings.Default.Save();
            }
            catch
            {
                MessageBox.Show("Kết nối thất bại!");
                
            }
        }

        private void txtMatKhau_EditValueChanged(object sender, EventArgs e)
        {

        }
    }
}
